package com.centit.app.controller;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.interfaces.Claim;
import com.centit.airplanebaseinfo.po.AirplaneBaseinfo;
import com.centit.airplanebaseinfo.service.AirplaneBaseinfoManager;
import com.centit.cxtj.service.CxtjManager;
import com.centit.dtjktxlog.service.JddtDtjktxlogManager;
import com.centit.fileserver.client.DefaultFileClient;
import com.centit.fileserver.client.po.FileStoreInfo;
import com.centit.flowNode.po.FlowNode;
import com.centit.flowNode.service.FlowNodeManager;
import com.centit.framework.common.JsonResultUtils;
import com.centit.framework.common.ResponseMapData;
import com.centit.framework.components.CodeRepositoryUtil;
import com.centit.framework.core.controller.BaseController;
import com.centit.framework.core.dao.CodeBook;
import com.centit.framework.ip.businessdata.po.InterfaceLog;
import com.centit.framework.ip.businessdata.service.InterfaceLogManager;
import com.centit.framework.ip.util.FileUploadUtil;
import com.centit.framework.ip.webservice.po.ResponseResult;
import com.centit.framework.model.basedata.IDataDictionary;
import com.centit.framework.model.basedata.IRoleInfo;
import com.centit.framework.model.basedata.IUnitInfo;
import com.centit.framework.model.basedata.IUserInfo;
import com.centit.framework.security.model.CentitPasswordEncoder;
import com.centit.framework.security.model.CentitUserDetails;
import com.centit.framework.system.po.UserInfo;
import com.centit.framework.system.service.SysUserManager;
import com.centit.ideaInfo.po.IdeaInfo;
import com.centit.ideaInfo.service.IdeaInfoManager;
import com.centit.jdghgl.service.JdghglManager;
import com.centit.support.algorithm.UuidOpt;
import com.centit.support.database.utils.PageDesc;
import com.centit.support.database.utils.QueryAndNamedParams;
import com.centit.support.database.utils.QueryUtils;
import com.centit.util.JwtToken;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * AirplaneBaseinfo  Controller.
 * create by scaffold 2020-03-13 
 * @author 脚手架，改成开发者的名字
 * app接口
*/
@RestController
@RequestMapping("/app")
public class AppController extends BaseController {
	private static final Log log = LogFactory.getLog(AppController.class);

	@Resource
	private CentitPasswordEncoder passwordEncoder;
	@Resource
	private JddtDtjktxlogManager jddtDtjktxlogMag;
	@Resource
	@NotNull
	private SysUserManager sysUserManager;
	@Resource
	protected InterfaceLogManager interfaceLogMag;
	@Resource
	private AirplaneBaseinfoManager airplaneBaseinfoMag;
	@Resource
	private JdghglManager jdghglMag;
	@Resource
	private IdeaInfoManager ideaInfoMag;
	@Resource
	private FlowNodeManager flowNodeMag;
	@Resource
	private JddtDtjktxlogManager jddtDtjktxlogManager;
	
	@Resource
	private CxtjManager cxtjMag;

	private static String code = "0";

	private static String desc = "请求成功";

	private static DefaultFileClient fileClient;
	
	private static String uploaderpath = CodeRepositoryUtil.getSysConfigValue("uploaderpath");
	SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * 功能描述: 用户名密码登录
	 *
	 * @param:登录名，密码经过服务器端第一次返回的公钥加密之后的，客户端生成的RSA公钥
	 * @return:
	 * @auther: 张帅
	 */
	@RequestMapping(value = "/appLogin", method = RequestMethod.POST)
	public ResponseResult<JSONObject> appLogin(HttpEntity<String> requestEntity, HttpServletRequest request) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		String bodyJson = requestEntity.getBody();
		JSONObject json = JSONObject.parseObject(bodyJson);
		String devId = (String) json.get("devId");
		String loginName = (String) json.get("loginName");
		Pattern p = Pattern.compile("\\s*|\t|\r|\n");
		Matcher m = p.matcher(loginName);
		loginName = m.replaceAll("");
		String pwd = (String) json.get("pwd");
		CacheManager cacheManager = CacheManager.newInstance();
		Cache cache = cacheManager.getCache(devId);
		code = "0";

		desc = "请求成功";
		// 使用缓存
		/*
		 * Element element = cache.get("privateKey"); String privateKey=
		 * element.getValue().toString();
		 */// 取出私钥准备解密密码
		try {
			/*
			 * byte[] pwd1=CreateSecrteKey.decryptByPrivateKey(pwd.getBytes(),
			 * privateKey);
			 */// 私钥解密之后的得到正确的密码
			// 传加密数据时使用
			// pwd = Des3.decode(pwd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		UserInfo userInfo = sysUserManager.loadUserByLoginname(loginName);
		if (userInfo != null) {
			Boolean enBool = passwordEncoder.isPasswordValid(userInfo.getUserPin(), pwd,
					userInfo.getUserCode()); /*
												 * passwordEncoder.encodePassword(
												 * pwd,userInfo.getUserCode());
												 */
			if (enBool) {
				try {
					JSONObject jsonObject = new JSONObject();
					String token = JwtToken.createToken(userInfo.getUserCode(), userInfo.getLoginName());
					String primaryUnit = userInfo.getPrimaryUnit();
					String primaryName = CodeRepositoryUtil.getUnitName(primaryUnit);
					jsonObject.put("usercode", userInfo.getUserCode());
					jsonObject.put("username", userInfo.getUserName());
					jsonObject.put("unitname", primaryName);
					jsonObject.put("unitcode", primaryUnit);
					jsonObject.put("token", token);
					result.setData(jsonObject);
					// 建立一个缓存实例
					Cache memoryOnlyCache = null;
					// 在内存管理器中添加缓存实例
					Element elementToekn = new Element("token", token);
					memoryOnlyCache = new Cache(devId, 5000, false, false, 0, 3600);
					cacheManager.removeCache(memoryOnlyCache.getName());// 去除同名称的
																		// devid设备主键，唯一，对于每个用户
					cacheManager.addCache(memoryOnlyCache);// 本行和下面那行两行顺序不能颠倒
					memoryOnlyCache.put(elementToekn);
				} catch (Exception e) {
					e.printStackTrace();
				}

			} else {
				code = "1";
				desc = "用户密码不正确";
			}
		} else {
			code = "1";
			desc = "用户登录名不存在";
		}
		result.setCode(code);
		result.setDesc(desc);
		// 记录调用日志
		InterfaceLog interfaceLog = new InterfaceLog();
		interfaceLog.setRecordid(UuidOpt.getUuidAsString());
		interfaceLog.setCreater(getLoginUserCode(request));
		interfaceLog.setCreateTime(new Date());
		interfaceLog.setMethodflag("appRsaKey");
		interfaceLog.setSystemflag("appLoginKey");
		interfaceLog.setResponse("code:" + code + ";desc:" + desc);
		interfaceLog.setYwflag("0");
		interfaceLog.setResultflag("T");
		this.interfaceLogMag.saveNewObject(interfaceLog);
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：获取待办信息
	 * @author 张帅
	 * @date: 2020年4月22日 下午5:11:32
	 */
	@RequestMapping(value = "/getDbInfo", method = RequestMethod.POST)
	public ResponseResult<JSONArray> getDbInfo(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		String bodyJson = requestEntity.getBody();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
		if (paramMap == null) {
			paramMap = new HashMap<String, Object>();
		}
		String userCode = (String) paramMap.get("usercode");
		Map<String, Object> searchColumn = new HashMap<String, Object>();
		searchColumn.put("dataValid", "T");
		searchColumn.put("userCode", userCode);
		JSONArray jsonArrayObjects = airplaneBaseinfoMag.listDb(searchColumn, null);
		result.setCode(code);
		result.setDesc(desc);
		result.setData(jsonArrayObjects);
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：获取合同到期监控
	 * @author 张帅
	 * @date: 2020年4月22日 下午5:13:07
	 */
	@RequestMapping(value = "/getHtEnd", method = RequestMethod.POST)
	public ResponseResult<JSONArray> getHtEnd(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		PageDesc pageDesc = new PageDesc();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String pageSize = paramMap.get("pageSize") != null ? (String) paramMap.get("pageSize") : "10";
			String pageNo = paramMap.get("pageNo") != null ? (String) paramMap.get("pageNo") : "1";
			pageDesc.setPageNo(Integer.parseInt(pageNo));
			pageDesc.setPageSize(Integer.parseInt(pageSize));
			UserInfo userInfo = sysUserManager.getObjectById(userCode);
			String primaryUnit = userInfo.getPrimaryUnit();
			String tableName = "合同到期监控";
			String jksxId = "22cf64f0983b4eafbdbce3e039b0f86b";
			if (primaryUnit.equals("12") || primaryUnit.equals("10")) {
				tableName = "合同到期监控";
				jksxId = "22cf64f0983b4eafbdbce3e039b0f86b";
			} else {
				tableName = "电台执照到期监控";
				jksxId = "76143c2e0eb74191ad4e6f486fa2ad0d";
			}
			Map<String, Object> searchColumn = new HashMap<String, Object>();
			searchColumn.put("clStatus", "1");
			searchColumn.put("jksxId", jksxId);
			JSONArray jsonArrayObjects = jddtDtjktxlogMag.listAsJSONArray(searchColumn, pageDesc);
			for (int i = 0; i < jsonArrayObjects.size(); i++) {
				JSONObject obj = jsonArrayObjects.getJSONObject(i);
				if (StringUtils.isNotEmpty(obj.getString("dqDate"))) {
					obj.put("dqDate", spf.format(obj.getDate("dqDate")));
				}
				if (StringUtils.isNotEmpty(obj.getString("jcStatus"))) {
					obj.put("jcStatusText", CodeRepositoryUtil.getValue("JC_STATUS", obj.getString("jcStatus")));
				}
				if (StringUtils.isNotEmpty(obj.getString("clStatus"))) {
					obj.put("clStatusText", CodeRepositoryUtil.getValue("CL_STATUS", obj.getString("clStatus")));
				}
				if (StringUtils.isNotEmpty(obj.getString("txtype"))) {
					obj.put("txtypeText", CodeRepositoryUtil.getValue("TXTYPE", obj.getString("txtype")));
				}
				if (StringUtils.isNotEmpty(obj.getString("nature"))) {
					obj.put("nature", CodeRepositoryUtil.getValue("AIRXZ", obj.getString("nature")));
				}
				if (StringUtils.isNotEmpty(obj.getString("syday"))) {
					String bz = "";
					int sydayInt = Integer.parseInt(obj.getString("syday"));
					if(StringUtils.isNotEmpty(obj.getString("alarmR"))&&StringUtils.isNotEmpty(obj.getString("alarmY"))){
						int alarmRInt = Integer.parseInt(obj.getString("alarmR"));
						int alarmYInt = Integer.parseInt(obj.getString("alarmY"));
						if(sydayInt<=alarmRInt){
							bz = "1";
						}else if(sydayInt<=alarmYInt){
							bz = "2";
						}
					}
					obj.put("bz", bz);
				}
				
				
			}
			result.setCode(code);
			result.setDesc(desc);
			result.setCount(tableName);
			result.setData(jsonArrayObjects);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：获取飞机信息列表
	 * @author 张帅
	 * @date: 2020年4月22日 下午5:57:33
	 */
	@RequestMapping(value = "/getAirinfoList", method = RequestMethod.POST)
	public ResponseResult<JSONArray> getAirinfoList(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		PageDesc pageDesc = new PageDesc();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String airModel = paramMap.get("airModel") != null ? (String) paramMap.get("airModel") : "";
			String ccxlh = paramMap.get("ccxlh") != null ? (String) paramMap.get("ccxlh") : "";
			String sign = paramMap.get("sign") != null ? (String) paramMap.get("sign") : "";
			String nature = paramMap.get("nature") != null ? (String) paramMap.get("nature") : "";
			String airZt = paramMap.get("airZt") != null ? (String) paramMap.get("airZt") : "";
			String status = paramMap.get("status") != null ? (String) paramMap.get("status") : "";
			String pageSize = paramMap.get("pageSize") != null ? (String) paramMap.get("pageSize") : "10";
			String pageNo = paramMap.get("pageNo") != null ? (String) paramMap.get("pageNo") : "1";
			pageDesc.setPageNo(Integer.parseInt(pageNo));
			pageDesc.setPageSize(Integer.parseInt(pageSize));
			Map<String, Object> searchColumn = new HashMap<String, Object>();
			searchColumn.put("dataValid", "T");
			searchColumn.put("airModel", airModel);
			searchColumn.put("ccxlh", ccxlh);
			searchColumn.put("sign", sign);
			searchColumn.put("status", status);
			searchColumn.put("nature", nature);
			searchColumn.put("airZt", airZt);
			JSONArray jsonArrayObjects = airplaneBaseinfoMag.getAirplaneBaseinfoList(searchColumn, pageDesc);
			for (int i = 0; i < jsonArrayObjects.size(); i++) {
				JSONObject jsonObject = jsonArrayObjects.getJSONObject(i);
				if (StringUtils.isNotEmpty(jsonObject.getString("airZt"))) {
					jsonObject.put("airZt", CodeRepositoryUtil.getValue("AIRZT", jsonObject.getString("airZt")));
				}
				if (StringUtils.isNotEmpty(jsonObject.getString("nature"))) {
					jsonObject.put("nature", CodeRepositoryUtil.getValue("AIRXZ", jsonObject.getString("nature")));
				}
			}
			result.setCode(code);
			result.setDesc(desc);
			result.setData(jsonArrayObjects);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：获取飞机详情
	 * @author 张帅
	 * @date: 2020年4月23日 上午9:16:26
	 */
	@RequestMapping(value = "/getAirInfo", method = RequestMethod.POST)
	public ResponseResult<JSONObject> getAirInfo(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String recId = (String) paramMap.get("recId");
			AirplaneBaseinfo airplaneBaseinfo = airplaneBaseinfoMag.getObjectById(recId);
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getAirZt())) {
				airplaneBaseinfo.setAirZt(CodeRepositoryUtil.getValue("AIRZT", airplaneBaseinfo.getAirZt()));
			}
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getNature())) {
				airplaneBaseinfo.setNature(CodeRepositoryUtil.getValue("AIRXZ", airplaneBaseinfo.getNature()));
			}
			JSONObject data = (JSONObject) JSONObject.toJSON(airplaneBaseinfo);
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getHt())) {
				JSONObject htjs = getFileInfo(airplaneBaseinfo.getHt());
				data.put("htFileName", htjs!=null?htjs.get("fileName"):"");
				data.put("htFileUrl", htjs!=null?htjs.get("fileUrl"):"");
				data.put("ht", htjs!=null?htjs.get("ids"):"");
			}
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getPw())) {
				JSONObject htjs = getFileInfo(airplaneBaseinfo.getPw());
				data.put("pwFileName", htjs!=null?htjs.get("fileName"):"");
				data.put("pwFileUrl", htjs!=null?htjs.get("fileUrl"):"");
				data.put("pw", htjs!=null?htjs.get("ids"):"");
			}
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getShz())) {
				JSONObject htjs = getFileInfo(airplaneBaseinfo.getShz());
				data.put("shzFileName", htjs!=null?htjs.get("fileName"):"");
				data.put("shzFileUrl", htjs!=null?htjs.get("fileUrl"):"");
				data.put("shz", htjs!=null?htjs.get("ids"):"");
			}
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getDtz())) {
				JSONObject htjs = getFileInfo(airplaneBaseinfo.getDtz());
				data.put("dtzFileName", htjs!=null?htjs.get("fileName"):"");
				data.put("dtzFileUrl", htjs!=null?htjs.get("fileUrl"):"");
				data.put("dtz", htjs!=null?htjs.get("ids"):"");
			}
			if (StringUtils.isNotEmpty(airplaneBaseinfo.getGjz())) {
				JSONObject htjs = getFileInfo(airplaneBaseinfo.getGjz());
				data.put("gjzFileName", htjs!=null?htjs.get("fileName"):"");
				data.put("gjzFileUrl", htjs!=null?htjs.get("fileUrl"):"");
				data.put("gjz", htjs!=null?htjs.get("ids"):"");
			}
			result.setCode(code);
			result.setDesc(desc);
			result.setData(data);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：获取数据字典数据（飞机性质，飞机状态，关联计划，用户树）
	 * @author 张帅
	 * @date: 2020年4月23日 下午1:50:55
	 */
	@RequestMapping(value = "/getDictData", method = RequestMethod.POST)
	public ResponseResult<JSONObject> getDictData(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			JSONObject data = new JSONObject();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			// 飞机性质
			List<? extends IDataDictionary> airXzs = CodeRepositoryUtil.getDictionary("AIRXZ");
			JSONArray airXzss = (JSONArray) JSONArray.toJSON(airXzs);
			data.put("airXzs", airXzss);
			// 飞机状态
			List<? extends IDataDictionary> airZts = CodeRepositoryUtil.getDictionary("AIRZT");
			JSONArray airZtss = (JSONArray) JSONArray.toJSON(airZts);
			data.put("airZts", airZtss);
			// 关联计划
			Map<String, Object> searchColumn = new HashMap<String, Object>();
			searchColumn.put("ghStatus", "1");
			searchColumn.put("dataValid", "T");
			searchColumn.put(CodeBook.SELF_ORDER_BY, " gh_Gxdate desc");
			JSONArray jsonArrayObjects = jdghglMag.listObjectsAsJson(searchColumn, null);
			data.put("jdghgls", jsonArrayObjects);
			//部门人员树表
			JSONArray array=new JSONArray();
			List<IUserInfo> userList=CodeRepositoryUtil.getAllUsers("T");
			userList.removeIf(u->"U00001".equals(u.getPrimaryUnit()));
			List<IUnitInfo> unitList=CodeRepositoryUtil.getAllUnits("T");
			unitList.removeIf(u->"U00001".equals(u.getUnitCode()));
			for(int i=0;i<unitList.size();i++){
				IUnitInfo unit=unitList.get(i);
				JSONObject obj=new JSONObject();
				obj.put("id", "P"+unit.getUnitCode());
				obj.put("name", unit.getUnitName());
				obj.put("pid", "0");
				obj.put("orderno", unit.getUnitOrder());
				obj.put("nocheck", "true");
				array.add(obj);
			}
			for(int i=0;i<userList.size();i++){
				IUserInfo user=userList.get(i);
				JSONObject obj=new JSONObject();
				obj.put("id", user.getUserCode());
				obj.put("name", user.getUserName());
				obj.put("pid", "P"+user.getPrimaryUnit());
				obj.put("orderno", user.getUserOrder());
				array.add(obj);
			}
			//对用户数组进行排序
			data.put("userZtree", sortJSONArrayNew(array));
			data.put("uploaderpath",uploaderpath);
			result.setCode(code);
			result.setDesc(desc);
			result.setData(data);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 功能描述：增加飞机数据
	 * @author 张帅
	 * @date: 2020年4月23日 下午1:50:55
	 */
	@RequestMapping(value = "/addAirInfo", method = RequestMethod.POST)
	public ResponseResult<JSONObject> addAirInfo(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			JSONObject data = new JSONObject();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			AirplaneBaseinfo airplaneBaseinfo = JSONObject.parseObject(bodyJson, AirplaneBaseinfo.class);
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String recId = paramMap.get("recId") != null ? (String) paramMap.get("recId") : "";
			String nextUserId = (String) paramMap.get("nextUser");
			UserInfo userInfo = sysUserManager.getObjectById(userCode);
			AirplaneBaseinfo dbAirplaneBaseinfo  =     			
	    			airplaneBaseinfoMag.getObjectById( recId);
	        if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
	        	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
	        	dbAirplaneBaseinfo.setEditUsercode(userCode);
	        	dbAirplaneBaseinfo.setEditTime(new Date());
	        	if(airplaneBaseinfo.getStatus()!=null&&airplaneBaseinfo.getStatus().equals("1")){
	        		dbAirplaneBaseinfo.setAirZt("1");
	        		dbAirplaneBaseinfo.setStatus("1");
	            	System.out.println("启动流程****************************************");
	            	String jhId = airplaneBaseinfo.getGljh();
	            	//String jhName = jdghglMag.getObjectById(jhId).getGhName();
	            	String flowRecId=UuidOpt.getUuidAsString32();
	            	dbAirplaneBaseinfo.setFlowInsId(flowRecId);
	            	String ideaRecId=UuidOpt.getUuidAsString32();
	            	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(userCode);
	            	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(userInfo.getPrimaryUnit());
	            	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
	            	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
	            	//新增日志
	            	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),dbAirplaneBaseinfo.getRecId(),"飞机引进计划");
	            	ideaInfoMag.saveNewObject(ideaInfo);
	            	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,dbAirplaneBaseinfo.getRecId(),"飞机引进计划");
	            	ideaInfoMag.saveNewObject(ideaNext);
	            	
	            	
	            	//新增节点信息
	            	FlowNode node=new FlowNode();
	            	node.setFlowRecId(flowRecId);
	            	node.setRecId(UuidOpt.getUuidAsString32());
	            	node.setIdeaRecId(ideaRecId);
	            	node.setStatus("N");
	            	node.setNodeName("飞机引进计划");
	            	node.setNodeNum(1);
	            	node.setNextUserCode(nextUserId);
	            	node.setNextUserUnit(nextUnit.getUnitCode());
	            	node.setStatus("N");
	            	flowNodeMag.saveNewObject(node);
	            }
	        	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
	        } else {
	        	airplaneBaseinfo.setRecId(UuidOpt.getUuidAsString32());
	            airplaneBaseinfo.setDataValid("T");
	            airplaneBaseinfo.setInsTime(new Date());
	            airplaneBaseinfo.setInsUsercode(userCode);
	            if(StringUtils.isNoneBlank(airplaneBaseinfo.getStatus())&&airplaneBaseinfo.getStatus().equals("1")){
	            	airplaneBaseinfo.setStatus("1");
	            }else{
	            	airplaneBaseinfo.setStatus("0");
	            }
	            if(airplaneBaseinfo.getStatus()!=null&&airplaneBaseinfo.getStatus().equals("1")){
	        		airplaneBaseinfo.setAirZt("1");
	            	System.out.println("启动流程****************************************");
	            	String jhId = airplaneBaseinfo.getGljh();
	            	//String jhName = jdghglMag.getObjectById(jhId).getGhName();
	            	String flowRecId=UuidOpt.getUuidAsString32();
	            	airplaneBaseinfo.setFlowInsId(flowRecId);
	            	String ideaRecId=UuidOpt.getUuidAsString32();
	            	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(userCode);
	            	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(userInfo.getPrimaryUnit());
	            	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
	            	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
	            	//新增日志
	            	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),airplaneBaseinfo.getRecId(),"飞机引进计划");
	            	ideaInfoMag.saveNewObject(ideaInfo);
	            	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,airplaneBaseinfo.getRecId(),"飞机引进计划");
	            	ideaInfoMag.saveNewObject(ideaNext);
	            	
	            	
	            	//新增节点信息
	            	FlowNode node=new FlowNode();
	            	node.setFlowRecId(flowRecId);
	            	node.setRecId(UuidOpt.getUuidAsString32());
	            	node.setIdeaRecId(ideaRecId);
	            	node.setStatus("N");
	            	node.setNodeName("计划飞机引进");
	            	node.setNodeNum(1);
	            	node.setNextUserCode(nextUserId);
	            	node.setNextUserUnit(nextUnit.getUnitCode());
	            	node.setStatus("N");
	            	flowNodeMag.saveNewObject(node);
	            }
	            airplaneBaseinfoMag.saveNewObject(airplaneBaseinfo);//新增,注意主键赋值 UuidUtil.getTimeBasedUuid()，填写自己的业务时间，业务操作人等信息	
	        }
			result.setCode(code);
			result.setDesc(desc);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：办理流程
	 * @author 张帅
	 * @date:  2020年4月24日 上午11:16:26
	 */
	@RequestMapping(value = "/saveFlow", method = RequestMethod.POST)
	public ResponseResult<JSONObject> saveFlow(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			JSONObject data = new JSONObject();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			UserInfo userInfo = sysUserManager.getObjectById(userCode);
			String content = paramMap.get("transContent") != null ? (String) paramMap.get("transContent") : "";
			String recId = paramMap.get("recId") != null ? (String) paramMap.get("recId") : "";
			String nextUserId = paramMap.get("nextUserId") != null ? (String) paramMap.get("nextUserId") : "";
			String nextUserName = paramMap.get("nextUserName") != null ? (String) paramMap.get("nextUserName") : "";
			String flowRecId = paramMap.get("flowRecId") != null ? (String) paramMap.get("flowRecId") : "";
		   	 if(nextUserId!=null&&StringUtils.isNotBlank(nextUserId)&&StringUtils.isNotBlank(recId)){
		   		String flowState = paramMap.get("flowState") != null ? (String) paramMap.get("flowState") : "";
		   		//将待办理改为已办
		   		ideaInfoMag.updateLastIdeaInfo(flowRecId,userCode, content);
		   		//修改办理人节点信息
		   		flowNodeMag.updateFlowNodeStatus(flowRecId, userCode);
		   		
		   		IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
	        	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
	        	String ideaRecId=UuidOpt.getUuidAsString32();
		   		
	        	
	        	 	JSONObject obj=ideaInfoMag.getLastIdeaInfo(flowRecId);
		   			//新增下一个人办理日志
		   			IdeaInfo ideaNext=new IdeaInfo(ideaRecId,flowRecId,nextUser,nextUnit,"待办理",null,recId,obj==null?"":obj.getString("ideaType"));
		        	ideaInfoMag.saveNewObject(ideaNext);
		        	
		        	//新增下一个办理人信息
			   		Integer maxNum=flowNodeMag.getMaxNum(flowRecId);	   		
			   		FlowNode node=new FlowNode();
		        	node.setFlowRecId(flowRecId);
		        	node.setRecId(UuidOpt.getUuidAsString32());
		        	node.setIdeaRecId(ideaRecId);
		        	node.setStatus("N");
		        	node.setNodeName("");
		        	node.setNodeNum(maxNum+1);
		        	node.setNextUserCode(nextUserId);
		        	node.setNextUserUnit(nextUnit.getUnitCode());
		        	node.setStatus("N");
		        	flowNodeMag.saveNewObject(node);
		   	 }else{
		   		String flowState = paramMap.get("flowState") != null ? (String) paramMap.get("flowState") : "";
		   		//将待办理改为已办
		   		ideaInfoMag.updateLastIdeaInfo(flowRecId, userCode, content);
		   		//修改办理人节点信息
		   		flowNodeMag.updateFlowNodeStatus(flowRecId, userCode);
		   		AirplaneBaseinfo	airplaneBaseinfo = airplaneBaseinfoMag.getObjectById(recId);
		   		if("End".equals(flowState)){
		   			airplaneBaseinfo.setStatus("2");//流程结束 使用
		    		airplaneBaseinfo.setAirZt("2");
		    		airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
		   		}else{
		   			
		   			airplaneBaseinfo.setStatus("2");//流程结束 注销
		   			if(airplaneBaseinfo.getCzType()==null||StringUtils.isBlank(airplaneBaseinfo.getCzType())){
		   				airplaneBaseinfo.setAirZt("2");
		   			}else{
		   				airplaneBaseinfo.setAirZt("3");
		   			}
	         		airplaneBaseinfo.setOffDate(new Date());
	         		airplaneBaseinfoMag.mergeObject(airplaneBaseinfo);
		   		}
		   	 }
			result.setCode(code);
			result.setDesc(desc);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}

	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：保存飞机基础信息
	 * @author 张帅
	 * @date:  2020年4月26日 上午10:16:41
	 */
	@RequestMapping(value = "/saveAir", method = RequestMethod.POST)
	public ResponseResult<JSONObject> saveAir(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			AirplaneBaseinfo airplaneBaseinfo = JSONObject.parseObject(bodyJson, AirplaneBaseinfo.class);
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String recId = paramMap.get("recId") != null ? (String) paramMap.get("recId") : "";
			UserInfo userInfo = sysUserManager.getObjectById(userCode);
			AirplaneBaseinfo dbAirplaneBaseinfo  =     			
	     			airplaneBaseinfoMag.getObjectById( recId);
	         if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
	         	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
	         	dbAirplaneBaseinfo.setEditUsercode(userCode);
	         	dbAirplaneBaseinfo.setEditTime(new Date());
	         	airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
	         }
			result.setCode(code);
			result.setDesc(desc);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：变更飞机信息
	 * @author 张帅
	 * @date:  2020年4月26日 上午10:39:30
	 */
	@RequestMapping(value = "/bgAirBase", method = RequestMethod.POST)
	public ResponseResult<JSONObject> bgAirBase(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			AirplaneBaseinfo airplaneBaseinfo = JSONObject.parseObject(bodyJson, AirplaneBaseinfo.class);
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String logId = paramMap.get("logId") != null ? (String) paramMap.get("logId") : "";
			String recId = paramMap.get("recId") != null ? (String) paramMap.get("recId") : "";
			String bgtype = paramMap.get("bgtype") != null ? (String) paramMap.get("bgtype") : "";
			String nextUserId = paramMap.get("nextUserId") != null ? (String) paramMap.get("nextUserId") : "";
			UserInfo userInfo = sysUserManager.getObjectById(userCode);
			AirplaneBaseinfo dbAirplaneBaseinfo  =     			
	    			airplaneBaseinfoMag.getObjectById( recId);
			 if (null != dbAirplaneBaseinfo) {//如果数据库数据存在，则是更新操作
		        	dbAirplaneBaseinfo .copyNotNullProperty(airplaneBaseinfo);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
		        	dbAirplaneBaseinfo.setEditUsercode(userCode);
		        	dbAirplaneBaseinfo.setEditTime(new Date());
		        	dbAirplaneBaseinfo.setStatus("1");
		        	if(StringUtils.isNotBlank(logId)){
		        		jddtDtjktxlogManager.handle(logId);
		        	}
		            	if(StringUtils.isNoneBlank(bgtype)){
		            		String name = "融资、出租人变更";
		            		if(!bgtype.equals("1")){
		            			 name = "占有权及IDERA办理";
		            		}
		                 	String flowRecId=UuidOpt.getUuidAsString32();
		                	airplaneBaseinfo.setFlowInsId(flowRecId);
		                	dbAirplaneBaseinfo.setFlowInsId(flowRecId);
		                	String ideaRecId=UuidOpt.getUuidAsString32();
		                	IUserInfo user= CodeRepositoryUtil.getUserInfoByCode(userCode);
		                	IUnitInfo unitInfo= CodeRepositoryUtil.getUnitInfoByCode(userInfo.getPrimaryUnit());
		                	IUserInfo nextUser= CodeRepositoryUtil.getUserInfoByCode(nextUserId);
		                	IUnitInfo nextUnit= CodeRepositoryUtil.getUnitInfoByCode(nextUser.getPrimaryUnit());
		                	//新增日志
		                	IdeaInfo ideaInfo=new IdeaInfo(ideaRecId,flowRecId,user,unitInfo,"已办",new Date(),dbAirplaneBaseinfo.getRecId(),"日常维护变更");
		                	ideaInfoMag.saveNewObject(ideaInfo);
		                	IdeaInfo ideaNext=new IdeaInfo(UuidOpt.getUuidAsString32(),flowRecId,nextUser,nextUnit,"待办理",null,dbAirplaneBaseinfo.getRecId(),"日常维护变更");
		                	ideaInfoMag.saveNewObject(ideaNext);
		                	
		                	
		                	//新增节点信息
		                	FlowNode node=new FlowNode();
		                	node.setFlowRecId(flowRecId);
		                	node.setRecId(UuidOpt.getUuidAsString32());
		                	node.setIdeaRecId(ideaRecId);
		                	node.setStatus("N");
		                	node.setNodeName("日常维护变更");
		                	node.setNodeNum(1);
		                	node.setNextUserCode(nextUserId);
		                	node.setNextUserUnit(nextUnit.getUnitCode());
		                	node.setStatus("N");
		                	flowNodeMag.saveNewObject(node);
		            	}
		            airplaneBaseinfoMag.mergeObject(dbAirplaneBaseinfo);
		            	}
			result.setCode(code);
			result.setDesc(desc);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：办理日志接口
	 * @author 张帅
	 * @date:  2020年4月29日 上午9:58:39
	 */
	@RequestMapping(value = "/listIdeaLog", method = RequestMethod.POST)
	public ResponseResult<JSONArray> listIdeaLog(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String flowRecId = paramMap.get("flowRecId") != null ? (String) paramMap.get("flowRecId") : "";
			 Map<String, Object> searchColumn = new HashMap<String, Object>();
	    	searchColumn.put("dataValid", "T");
	    	searchColumn.put("flowRecId", flowRecId);
	    	searchColumn.put(CodeBook.SELF_ORDER_BY, "create_time asc");
	    	JSONArray jsonArrayObjects = ideaInfoMag.listIdeaInfo(searchColumn, null);
			result.setCode(code);
			result.setDesc(desc);
			result.setData(jsonArrayObjects);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：过去当先最后一条办理日志
	 * @author 张帅
	 * @date:  2020年5月6日 下午4:22:46
	 */
	@RequestMapping(value = "/selFlow", method = RequestMethod.POST)
	public ResponseResult<JSONObject> selFlow(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			String bodyJson = requestEntity.getBody();
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap = JSONObject.parseObject(bodyJson, paramMap.getClass());
			if (paramMap == null) {
				paramMap = new HashMap<String, Object>();
			}
			String userCode = (String) paramMap.get("usercode");
			String recId = paramMap.get("recId") != null ? (String) paramMap.get("recId") : "";
			AirplaneBaseinfo module=airplaneBaseinfoMag.getObjectById(recId);
	    	JSONObject o=ideaInfoMag.getLastIdeaInfo(module.getFlowInsId());
			result.setCode(code);
			result.setDesc(desc);
			result.setData(o);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：机龄分析（饼图）
	 * @author 张帅
	 * @date:  2020年5月12日 上午9:08:48
	 */
	@RequestMapping(value = "/getJlfxList", method = RequestMethod.GET)
	public ResponseResult<JSONObject> getJlfxList(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONObject> result = new ResponseResult<JSONObject>();
		try {
			
			Map<String, Object> searchColumn = convertSearchColumn(request); 
			JSONObject o =  cxtjMag.getJlfxList(searchColumn).getJSONObject(0);
			result.setCode(code);
			result.setDesc(desc);
			result.setData(o);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	/**
	 * @param requestEntity
	 * @param request
	 * @param response
	 * @return 
	 * 功能描述：飞机引进分析（柱状）
	 * @author 张帅
	 * @date:  2020年5月12日 上午9:12:50
	 */
	@RequestMapping(value = "/fjyjfx", method = RequestMethod.GET)
	public ResponseResult<JSONArray> fjyjfx(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		try {
			
			Map<String, Object> searchColumn = convertSearchColumn(request); 
			JSONArray o = cxtjMag.fjyjfx(searchColumn);
			result.setCode(code);
			result.setDesc(desc);
			result.setData(o);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	@RequestMapping(value = "/getFjzlxzList", method = RequestMethod.GET)
	public ResponseResult<JSONArray> getFjzlxzList(HttpEntity<String> requestEntity, HttpServletRequest request,
			HttpServletResponse response) {
		ResponseResult<JSONArray> result = new ResponseResult<JSONArray>();
		try {
			
			Map<String, Object> searchColumn = convertSearchColumn(request); 
			JSONArray o = cxtjMag.getFjzlxzList(searchColumn);
			result.setCode(code);
			result.setDesc(desc);
			result.setData(o);
		} catch (Exception e) {
			result.setCode("-1");
			result.setDesc("请求失败");
		}
		return result;
	}
	
	public static JSONObject getFileInfo(String fileIds) {
		JSONObject json = new JSONObject();
		// 获取fileClient值
		fileClient = FileUploadUtil.getFileClient();
		String fileName = "";
		String fileUrl = "";
		String ids = "";
		
			String[] fileId = null;
			if (StringUtils.isNotBlank(fileIds)) {
				fileId = fileIds.split(",");
			}
			if (fileId != null && fileId.length > 0) {
				FileStoreInfo fileStoreInfo;
				JSONObject jsonObject;
				for (int i = 0; i < fileId.length; i++) {
					if(StringUtils.isNotBlank(fileId[i])&&!"null".equals(fileId[i])){
					try {
					fileStoreInfo = fileClient.getFileStoreInfo(fileClient.getHttpClient(), fileId[i]);
					fileName+=fileStoreInfo.getFileName()+",";
					fileUrl+=uploaderpath + "/service/download/pfile/" + fileStoreInfo.getFileId()+",";
					ids += fileId[i]+",";
					} catch (Exception e) {
						System.out.println(e.getMessage());  
					}
					}
				}
			}
			json.put("ids", ids);
			json.put("fileName", fileName);
			json.put("fileUrl", fileUrl);
		
		return json;
	}
	public static JSONArray sortJSONArrayNew(JSONArray jsonArr){
        for (int i = 0; i < jsonArr.size(); i++) {
        	if(jsonArr.getJSONObject(i).get("orderno")==null||StringUtils.isBlank(jsonArr.getJSONObject(i).get("orderno").toString())){
        		continue;
        	}
            long l = Long.parseLong(jsonArr.getJSONObject(i).get("orderno").toString());
            for (int j = i + 1; j < jsonArr.size(); j++) {
            	if(jsonArr.getJSONObject(j).get("orderno")==null||StringUtils.isBlank(jsonArr.getJSONObject(j).get("orderno").toString())){
            		continue;
            	}
                long nl = Long.parseLong(jsonArr.getJSONObject(j).get("orderno").toString());
                if (l > nl) {
                    JSONObject temp = jsonArr.getJSONObject(j);
                    l = nl;
                    jsonArr.set(j, jsonArr.getJSONObject(i));
                    jsonArr.set(i, temp);
                }
            }
        }
        return jsonArr;
    }
}
